package com.evenmo.hrms.mapper.oldmapper;

import com.evenmo.hrms.mapper.oldmapper.dynaSqlProvider.EmployeeDynaSqlProvider;
import com.evenmo.hrms.pojo.Employee;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

@Mapper
public interface EmployeeMapper {
    //根据参数查询员工总数

    /**
     * 根据参数查询员工总数
     *
     * @param employee 查询参数，用employee对象封装
     * @return 符合条件的员工信息
     */
    @SelectProvider(type = EmployeeDynaSqlProvider.class, method = "countByParams")
    public int countByParams(Employee employee);
    //根据参数动态查询员工

    /**
     * 根据参数动态查询员工
     *
     * @param employee 查询的参数，用employee对象封装
     * @return 符合条件的员工列表
     */
    @SelectProvider(type = EmployeeDynaSqlProvider.class, method = "selectByparams")
    @ResultMap("employeeResultMapHaveJobAndDept")
    public List<Employee> selectByparams(Employee employee);

    /**
     * 动态插入员工
     *
     * @param employee 插入的员工信息
     * @return 插入的数目
     */
    @InsertProvider(type = EmployeeDynaSqlProvider.class, method = "insertByParams")
    @Options(keyProperty = "id", useGeneratedKeys = true)
    public int insertByParams(Employee employee);

    /**
     * 根据ID删除员工
     *
     * @param id 员工ID
     * @return 删除的数目
     */
    @Delete("delete from employee where id=#{id}")
    public int deleteById(Integer id);
    //根据ID查询员工

    /**
     * 根据ID查询员工
     *
     * @param id 员工ID
     * @return 符合条件的员工
     */
    @Select("select * from employee where id=#{id}")
    @Results(id = "employeeResultMapHaveJobAndDept",value={
            @Result(column = "jobId",property = "jobId"),
            @Result(column = "jobId",property = "job",one=@One(
                    select = "com.evenmo.hrms.mapper.oldmapper.JobMapper.selectById",fetchType = FetchType.EAGER
            )),
            @Result(column = "deptId",property = "deptId"),
            @Result(column = "deptId",property = "dept",one=@One(
                    select = "com.evenmo.hrms.mapper.oldmapper.DeptMapper.selectById",fetchType = FetchType.EAGER
            ))

    })
    public Employee selectById(Integer id);
    //动态修改员工

    /**
     * 动态修改员工
     *
     * @param employee 要修改的员工信息
     * @return 修改的数量
     */
    @UpdateProvider(type = EmployeeDynaSqlProvider.class, method = "updateByParams")
    public int updateByParams(Employee employee);

    /**
     * 查询所有的员工
     * @return 所有的员工列表
     */
    List<Employee> selectEmployees();
}
